<?xml version="1.0"?>

<st-source>
<time-stamp>From VisualWorks® NonCommercial, 7.6 of March 3, 2008 on March 12, 2009 at 5:17:11 pm</time-stamp>
<!-- Package SupplyChain* -->


<name-space>
<name>SupplyChain</name>
<environment>Smalltalk</environment>
<private>false</private>
<imports>
			private Smalltalk.*
			</imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</name-space>

<class>
<name>DomainTest</name>
<environment>SupplyChain</environment>
<super>XProgramming.SUnit.TestCase</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>inventory i1 i2 i3 i4 i5 </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</class>

<comment>
<class-id>SupplyChain.DomainTest</class-id>
<body>This is the provided test class for M1.  You should not need to edit the class yourself.

To run, either install the RBSunit extension parcel and run from the system browser OR

highlight this code

TestRunner open

and doit.

Instance Variables:
	i1	&lt;Item&gt; a test item instance
	i2	&lt;Item&gt;	a test item instance
	i3	&lt;Item&gt;	a test item instance
	i4	&lt;Item&gt;	a test item instance
	i5	&lt;Item&gt;	a test item instance
	inventory	&lt;Inventory&gt;	an instance of the inventory class for test

</body>
</comment>

<class>
<name>CCS</name>
<environment>SupplyChain</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>posList supplierList </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</class>

<class>
<name>POS</name>
<environment>SupplyChain</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>posInventory name parentCcs sellPolicy </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</class>

<class>
<name>Inventory</name>
<environment>SupplyChain</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>items </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</class>

<comment>
<class-id>SupplyChain.Inventory</class-id>
<body>Inventory has not been commented.  The comment should state the purpose of the class and also explain any unobvious aspects of the implementation.

Instance Variables:
	items	&lt;OrderedCollection&gt;	 the collection of inventory items

</body>
</comment>

<class>
<name>Invoice</name>
<environment>SupplyChain</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>requestedItems processed </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</class>

<class>
<name>Supplier</name>
<environment>SupplyChain</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>supplierInventory name parentCcs </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</class>

<class>
<name>Item</name>
<environment>SupplyChain</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>name buyPrice sellPrice sku quantity reorderPoint </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</class>

<comment>
<class-id>SupplyChain.Item</class-id>
<body>This represents a single item in the inventory

Instance Variables:
	buyPrice	&lt;Integer&gt;	description of buyPrice
	name	&lt;String&gt;	description of name
	quantity	&lt;Integer&gt;	description of quantity
	reorderPoint	&lt;Integer&gt;	description of reorderPoint
	sellPrice	&lt;Integer&gt;	description of sellPrice
	sku	&lt;String&gt;	description of sku

</body>
</comment>









<methods>
<class-id>SupplyChain.Supplier class</class-id> <category>instance creation</category>

<body package="SupplyChain" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>SupplyChain.Supplier</class-id> <category>initialize-release</category>

<body package="SupplyChain" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."

	name := 'Unnamed Supplier'.
	supplierInventory := Inventory new.
	^self</body>
</methods>

<methods>
<class-id>SupplyChain.Supplier</class-id> <category>accessing</category>

<body package="SupplyChain" selector="supplierInventory:">supplierInventory: anObject
	supplierInventory := anObject</body>

<body package="SupplyChain" selector="name">name
	^name</body>

<body package="SupplyChain" selector="supplierInventory">supplierInventory
	^supplierInventory</body>

<body package="SupplyChain" selector="parentCcs:">parentCcs: anObject
	parentCcs := anObject</body>

<body package="SupplyChain" selector="parentCcs">parentCcs
	^parentCcs</body>

<body package="SupplyChain" selector="name:">name: anObject
	name := anObject</body>
</methods>


<methods>
<class-id>SupplyChain.DomainTest class</class-id> <category>instance creation</category>

<body package="SupplyChain" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>SupplyChain.DomainTest</class-id> <category>accessing</category>

<body package="SupplyChain" selector="i1:">i1: anObject
	i1 := anObject</body>

<body package="SupplyChain" selector="i5:">i5: anObject
	i5 := anObject</body>

<body package="SupplyChain" selector="i4">i4
	^i4</body>

<body package="SupplyChain" selector="i4:">i4: anObject
	i4 := anObject</body>

<body package="SupplyChain" selector="inventory">inventory
	^inventory</body>

<body package="SupplyChain" selector="i3">i3
	^i3</body>

<body package="SupplyChain" selector="i2">i2
	^i2</body>

<body package="SupplyChain" selector="i5">i5
	^i5</body>

<body package="SupplyChain" selector="i1">i1
	^i1</body>

<body package="SupplyChain" selector="i3:">i3: anObject
	i3 := anObject</body>

<body package="SupplyChain" selector="i2:">i2: anObject
	i2 := anObject</body>

<body package="SupplyChain" selector="inventory:">inventory: anObject
	inventory := anObject</body>
</methods>

<methods>
<class-id>SupplyChain.DomainTest</class-id> <category>Running</category>

<body package="SupplyChain" selector="setUp">setUp
   "Create test objects.  This is called before every individual test"
   inventory := Inventory new.
   i1 := Item named: 'Video Game' sku:'89X999'.
   i2 := Item named: 'TV' sku: '99Z837'.
   i3 := Item named: 'VCR' sku: '54Y3632'.
   i4 := Item named: 'PC' sku: '01P6373'.
   i5 := Item named: 'Laptop' sku: '11F4732'.</body>

<body package="SupplyChain" selector="testItemPotentialProfit">testItemPotentialProfit
   i1 buyPrice: 10.
   i1 sellPrice: 35.
   i1 quantity: 3.
   self assert: i1 potentialProfit = 75.</body>

<body package="SupplyChain" selector="testGetReorderItems">testGetReorderItems
   | coll |
   self setUpPrices.
   coll := inventory getReorderItems.
   self assert: coll size = 2.
   self assert: (coll includes: i1).
   self assert: (coll includes: i4).</body>

<body package="SupplyChain" selector="testInventoryPrintString">testInventoryPrintString
   self setUpPrices.
   self assert: inventory printString = 'An Inventory of 5 items valued at 634 dollars'.</body>

<body package="SupplyChain" selector="testInventoryPrintInventoryReport">testInventoryPrintInventoryReport
   self setUpPrices.
   inventory printInventoryReport</body>

<body package="SupplyChain" selector="testItemNeedsReorder">testItemNeedsReorder
   i1 reorderPoint: 10.
   i1 quantity: 15.
   self deny: i1 needsReorder.
   i1 quantity: 9.
   self assert: i1 needsReorder.</body>

<body package="SupplyChain" selector="testInventoryValue">testInventoryValue
   self setUpPrices.
   self assert: inventory inventoryValue = 634.</body>

<body package="SupplyChain" selector="testInventoryPotentialProfit">testInventoryPotentialProfit
   self setUpPrices.
   Transcript show: inventory potentialProfit printString.
   self assert: inventory potentialProfit = 442.</body>

<body package="SupplyChain" selector="testInventorySortBlock">testInventorySortBlock
   self addAllItems.
   self assert: (inventory items at: 1) = i5.
   self assert: (inventory items at: 5) = i1.
   inventory sortBlock: [ :a :b | a sku &lt; b sku].
  self assert: (inventory items at: 1) = i4.
  self assert: (inventory items at: 5) = i2.</body>

<body package="SupplyChain" selector="testItemValue">testItemValue
   self setUpPrices.
   self assert: i1 itemValue = 24.</body>

<body package="SupplyChain" selector="testInventoryAddItem">testInventoryAddItem
     self assert: inventory items size = 0.
     inventory addItem: i1.
    self assert: inventory items size = 1.
    self assert: (inventory items includes: i1).
    inventory addItem: i2.
    self assert: inventory items size = 2.
    self assert: (inventory items includes: i2).</body>

<body package="SupplyChain" selector="testInventoryRemoveItem">testInventoryRemoveItem
    self addAllItems.
    self assert: (inventory items includes: i3).
    inventory removeItem: i3.
    self deny: (inventory items includes: i3).</body>

<body package="SupplyChain" selector="testItemPrintString">testItemPrintString
   i1 quantity: 10.
   self assert: i1 printString = '10 Video Game 89X999'.</body>

<body package="SupplyChain" selector="testItemProfit">testItemProfit
   i1 buyPrice: 10.
   i1 sellPrice: 35.
   self assert: i1 profit = 25.</body>
</methods>

<methods>
<class-id>SupplyChain.DomainTest</class-id> <category>initialize-release</category>

<body package="SupplyChain" selector="addAllItems">addAllItems
   "utility method to add all the items to the inventory"
   inventory addItem: i1.
   inventory addItem: i2.
  inventory addItem: i3.
  inventory addItem: i4.
  inventory addItem: i5.</body>

<body package="SupplyChain" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."

	" *** Edit the following to properly initialize instance variables ***"
	inventory := nil.
	i1 := nil.
	i2 := nil.
	i3 := nil.
	i4 := nil.
	i5 := nil.
	" *** And replace this comment with additional initialization code *** "
	^self</body>

<body package="SupplyChain" selector="setUpPrices">setUpPrices
   " utility method to add all items and set the internal data for tests"
   self addAllItems.
   i1 buyPrice: 3.
   i1 sellPrice: 7.
   i1 quantity: 8.
   i1 reorderPoint: 9.
   i2 buyPrice: 22.
   i2 sellPrice: 36.
   i2 quantity: 7.
   i2 reorderPoint: 6.
   i3 buyPrice: 18.
   i3 sellPrice: 40.
   i3 quantity: 3.
   i3 reorderPoint: 3.
   i4 buyPrice: 19.
   i4 sellPrice: 36.
   i4 quantity: 6.
   i4 reorderPoint: 7.
   i5 buyPrice: 24.
   i5 sellPrice: 36.
   i5 quantity: 12.
   i5 reorderPoint: 10.</body>
</methods>


<methods>
<class-id>SupplyChain.Inventory class</class-id> <category>instance creation</category>

<body package="SupplyChain" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>SupplyChain.Inventory</class-id> <category>calculating</category>

<body package="SupplyChain" selector="potentialProfit">potentialProfit
   | sum |
   sum := 0.
   items do: [ :i | sum := sum + i potentialProfit].
   ^sum</body>

<body package="SupplyChain" selector="inventoryValue">inventoryValue
   |sum|
   sum := 0.
   items do: [ :i | sum := sum + i itemValue].
  ^ sum</body>
</methods>

<methods>
<class-id>SupplyChain.Inventory</class-id> <category>accessing</category>

<body package="SupplyChain" selector="removeItem:">removeItem: anItem
   items remove: anItem</body>

<body package="SupplyChain" selector="sortBlock:">sortBlock: aBlock
   items sortBlock: aBlock</body>

<body package="SupplyChain" selector="items">items
	^items</body>

<body package="SupplyChain" selector="addItem:">addItem: anItem
   items add: anItem</body>

<body package="SupplyChain" selector="items:">items: anObject
	items := anObject</body>

<body package="SupplyChain" selector="getReorderItems">getReorderItems
    ^ items select: [:e | e needsReorder ] </body>
</methods>

<methods>
<class-id>SupplyChain.Inventory</class-id> <category>printing</category>

<body package="SupplyChain" selector="printInventoryReport">printInventoryReport
   Transcript show: self printString ; cr.
    items do: [ :i | Transcript show: i printString; cr.].
    Transcript show: 'Total Inventory Potential Profit is ' ;show: self potentialProfit printString ; show: ' dollars'</body>

<body package="SupplyChain" selector="printString">printString
    ^ 'An Inventory of ', items size printString, ' items valued at ', self inventoryValue printString, ' dollars'.</body>
</methods>

<methods>
<class-id>SupplyChain.Inventory</class-id> <category>whatever</category>

<body package="SupplyChain" selector="findMostExpensive">findMostExpensive
	| mostExpensive |

	mostExpensive := items first.
	items do: [ :i | (i buyPrice &gt; mostExpensive) ifTrue: [mostExpensive := i] ].
	^mostExpensive</body>

<body package="SupplyChain" selector="findCheapest">findCheapest
	| cheapest |

	cheapest := items first.
	items do: [ :i | (i buyPrice &lt; cheapest) ifTrue: [cheapest := i] ].
	^cheapest</body>
</methods>

<methods>
<class-id>SupplyChain.Inventory</class-id> <category>initialize-release</category>

<body package="SupplyChain" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."

	" *** Edit the following to properly initialize instance variables ***"
	items := SortedCollection sortBlock: [ :a :b |  a name &lt; b name].
	" *** And replace this comment with additional initialization code *** "
	^self</body>
</methods>


<methods>
<class-id>SupplyChain.CCS class</class-id> <category>instance creation</category>

<body package="SupplyChain" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>SupplyChain.CCS</class-id> <category>accessing</category>

<body package="SupplyChain" selector="posList">posList
	^posList</body>

<body package="SupplyChain" selector="removeSupplier:">removeSupplier: aSupplier
	supplierList remove: aSupplier</body>

<body package="SupplyChain" selector="supplierList:">supplierList: anObject
	supplierList := anObject</body>

<body package="SupplyChain" selector="addSupplier:">addSupplier: aSupplier
	supplierList add:aSupplier</body>

<body package="SupplyChain" selector="supplierList">supplierList
	^supplierList</body>

<body package="SupplyChain" selector="addPos:">addPos: aPos
	posList add: aPos</body>

<body package="SupplyChain" selector="removePos:">removePos: aPos
	posList remove: aPos</body>

<body package="SupplyChain" selector="posList:">posList: anObject
	posList := anObject</body>
</methods>

<methods>
<class-id>SupplyChain.CCS</class-id> <category>initialize-release</category>

<body package="SupplyChain" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."

	posList := OrderedCollection new.
	supplierList := OrderedCollection new.
	^self</body>
</methods>


<methods>
<class-id>SupplyChain.Item class</class-id> <category>instance creation</category>

<body package="SupplyChain" selector="named:sku:">named: aName sku: aSku
    |inst|
    inst := super new initialize.
    inst name: aName.
    inst sku: aSku.
    ^ inst.</body>

<body package="SupplyChain" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>SupplyChain.Item</class-id> <category>initialize-release</category>

<body package="SupplyChain" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."

	" *** Edit the following to properly initialize instance variables ***"
	name := 'Default Item'.
	buyPrice := 0.
	sellPrice := 0.
	sku := '99999Z9999'.
	quantity := 0.
      reorderPoint:=0.
	" *** And replace this comment with additional initialization code *** "
	^self</body>
</methods>

<methods>
<class-id>SupplyChain.Item</class-id> <category>accessing</category>

<body package="SupplyChain" selector="name:">name: anObject
	name := anObject</body>

<body package="SupplyChain" selector="reorderPoint:">reorderPoint: anObject
	reorderPoint := anObject</body>

<body package="SupplyChain" selector="sku">sku
	^sku</body>

<body package="SupplyChain" selector="reorderPoint">reorderPoint
	^reorderPoint</body>

<body package="SupplyChain" selector="name">name
	^name</body>

<body package="SupplyChain" selector="buyPrice:">buyPrice: anObject
	buyPrice := anObject</body>

<body package="SupplyChain" selector="sellPrice">sellPrice
	^sellPrice</body>

<body package="SupplyChain" selector="sellPrice:">sellPrice: anObject
	sellPrice := anObject</body>

<body package="SupplyChain" selector="sku:">sku: anObject
	sku := anObject</body>

<body package="SupplyChain" selector="buyPrice">buyPrice
	^buyPrice</body>

<body package="SupplyChain" selector="quantity">quantity
	^quantity</body>

<body package="SupplyChain" selector="quantity:">quantity: anObject
	quantity := anObject</body>
</methods>

<methods>
<class-id>SupplyChain.Item</class-id> <category>printing</category>

<body package="SupplyChain" selector="printString">printString
   ^ quantity printString, ' ', name, ' ', sku</body>
</methods>

<methods>
<class-id>SupplyChain.Item</class-id> <category>whatever</category>

<body package="SupplyChain" selector="sellOne">sellOne
	quantity := quantity - 1.</body>
</methods>

<methods>
<class-id>SupplyChain.Item</class-id> <category>calculating</category>

<body package="SupplyChain" selector="potentialProfit">potentialProfit
   ^ self profit * quantity</body>

<body package="SupplyChain" selector="itemValue">itemValue
  ^ quantity * buyPrice</body>

<body package="SupplyChain" selector="needsReorder">needsReorder
   ^ quantity &lt; reorderPoint</body>

<body package="SupplyChain" selector="profit">profit
  ^ sellPrice - buyPrice</body>
</methods>


<methods>
<class-id>SupplyChain.Invoice class</class-id> <category>instance creation</category>

<body package="SupplyChain" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>SupplyChain.Invoice</class-id> <category>initialize-release</category>

<body package="SupplyChain" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."

	requestedItems := OrderedCollection new.
	processed := false.
	^self</body>
</methods>

<methods>
<class-id>SupplyChain.Invoice</class-id> <category>accessing</category>

<body package="SupplyChain" selector="processed:">processed: anObject
	processed := anObject</body>

<body package="SupplyChain" selector="processed">processed
	^processed</body>

<body package="SupplyChain" selector="requestedItems:">requestedItems: anObject
	requestedItems := anObject</body>

<body package="SupplyChain" selector="requestedItems">requestedItems
	^requestedItems</body>
</methods>


<methods>
<class-id>SupplyChain.POS class</class-id> <category>instance creation</category>

<body package="SupplyChain" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>SupplyChain.POS</class-id> <category>accessing</category>

<body package="SupplyChain" selector="name">name
	^name</body>

<body package="SupplyChain" selector="addItem:">addItem: anItem
	posInventory addItem: anItem.</body>

<body package="SupplyChain" selector="posInventory">posInventory
	^posInventory</body>

<body package="SupplyChain" selector="sellPolicy:">sellPolicy: anObject
	sellPolicy := anObject</body>

<body package="SupplyChain" selector="parentCcs:">parentCcs: anObject
	parentCcs := anObject</body>

<body package="SupplyChain" selector="posInventory:">posInventory: anObject
	posInventory := anObject</body>

<body package="SupplyChain" selector="parentCcs">parentCcs
	^parentCcs</body>

<body package="SupplyChain" selector="name:">name: anObject
	name := anObject</body>

<body package="SupplyChain" selector="sellPolicy">sellPolicy
	^sellPolicy</body>
</methods>

<methods>
<class-id>SupplyChain.POS</class-id> <category>whatever</category>

<body package="SupplyChain" selector="sell">sell
	| temp |

	sellPolicy = 'FIFO' ifTrue: [posInventory items first sellOne ].
	sellPolicy = 'LIFO' ifTrue: [posInventory items last sellOne].
	sellPolicy = 'CIF' ifTrue: [posInventory findCheapest sellOne].
	sellPolicy = 'EIF' ifTrue: [posInventory findMostExpensive sellOne].

	temp := posInventory getReorderItems.
	(temp size &gt; 0) ifTrue: ["DO SOMETHING WITH INVOICES HERE"].</body>
</methods>

<methods>
<class-id>SupplyChain.POS</class-id> <category>initialize-release</category>

<body package="SupplyChain" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."

	name := 'Unnamed POS'.
	posInventory := Inventory new.
	^self</body>
</methods>



</st-source>
